Skip to content

fix: Form collection, multiple dragging and dropping of parameters failed(#3745)#3874

Merged
wangdan-fit2cloud merged 1 commit intov1from
pr@v1@workfolw-drag
Aug 18, 2025
Merged

fix: Form collection, multiple dragging and dropping of parameters failed(#3745)#3874
wangdan-fit2cloud merged 1 commit intov1from
pr@v1@workfolw-drag

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Form collection, multiple dragging and dropping of parameters failed(#3745)

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 18, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

onDragHandle()
})
</script>
<style lang="scss" scoped></style>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks largely correct, but there are a few suggestions and improvements to consider:

  1. Cloning form_data.value.form_field_list:
    Since you're modifying an array directly (which can lead to unintended side effects), cloning it before performing operations is generally a good practice. However, this might be more relevant within the context of larger applications where multiple components might access the same data.

  2. Using map() for Array Operations:
    The current implementation uses filter, which creates a new filtered list instead of modifying the original. If you intend to perform modifications that change the order or remove elements, using map() would better fit the intent.

  3. Consistent Variable Naming:
    Ensure variable names like items.oldIndex, movedItem`, etc., are consistent with standard naming conventions.

  4. Handling Edge Cases:
    Consider adding checks to ensure that evt.oldIndex and evt.newIndex fall within valid bounds.

Here's a refined version of the code incorporating these suggestions:

const sync_form_field_list = () => {
  const fields = [
    { /* ... */ },
    { /* ... */ }
  ]
  set(props.nodeModel.properties.config, 'fields', fields)
  props.nodeModel.clear_next_node_field(false)
  onDragHandle()
}

const addFormCollectRef = ref<InstanceType<typeof AddFormCollect>>()
const editFormCollectRef = ref<InstanceType<typeof EditFormCollect>>()

function onDragHandle() {
  onEnd: (evt) => {
    if (evt.oldIndex === undefined || evt.newIndex === undefined) return
    const items = cloneDeep(form_data.value.form_field_list) // Clone the array first

    if (
      evt.oldIndex <= items.length - 1 &&
      evt.newIndex >= 0 && 
      evt.newIndex <= items.length - 1
    ) {
      const movedItem = items.splice(evt.oldIndex, 1)[0];
      items.splice(evt.newIndex, 0, movedItem);
      form_data.value.form_field_list = items;

      // Optionally emit event(s) here based on your requirements
    } else {
      console.warn(`Invalid drag index. Old Index: ${evt.oldIndex}, New Index: ${evt.newIndex}`);
    }
  },
})

onMounted(() => {
  set(props.nodeModel, 'validate', validate)
  sync_form_field_list();
  props.nodeModel.graphModel.eventCenter.emit('refresh_incoming_node_field');
})

These changes should help improve readability and robustness, especially in larger-scale projects.

@wangdan-fit2cloud wangdan-fit2cloud merged commit 98b58e7 into v1 Aug 18, 2025
4 of 5 checks passed
@wangdan-fit2cloud wangdan-fit2cloud deleted the pr@v1@workfolw-drag branch August 18, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants